package com.shuang.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shuang.common.TreeNode;
import com.shuang.service.DbGoodsClassService;


@Controller
@RequestMapping("/item")
public class ItemHanlder {
	
	@Resource(name="dbGoodsClassService")
	private DbGoodsClassService dbGoodsClassService;
	
	@RequestMapping("/classList")
	@ResponseBody
	public List<TreeNode> selClassList(@RequestParam(value="id", defaultValue="0")short parentId){
		return dbGoodsClassService.selClassList(parentId);
	}
	@RequestMapping("/front/classList")//前台查询
	@ResponseBody
	public List<TreeNode> selFrontClassList(@RequestParam(value="id", defaultValue="0")short parentId){
		return dbGoodsClassService.selClassList(parentId);
	}

	@RequestMapping("/addClass")
	@ResponseBody
	public Map<String ,Object> addClass(@RequestParam(value="parentId", defaultValue="0")short parentId ,String cName) throws Exception{
			return dbGoodsClassService.insertNewClass(parentId,cName);
	
	}
	
	@RequestMapping("/updateClass")
	@ResponseBody
	public Map<String ,Object> updateClass(@RequestParam(value="id", defaultValue="0")Long cId ,String cName,@RequestParam(value="parentId", defaultValue="0")Long parentId){
			return dbGoodsClassService.updateClass(cId,cName,parentId);
	
	}
	
	
	@RequestMapping("/removeClass")
	@ResponseBody
	public Map<String ,Object> removeClass(@RequestParam(value="id", defaultValue="0")Long cId ,short parentId){
			return dbGoodsClassService.removeClass(cId,parentId);
	
	}
	
	
	
}
